<template>
    <div class="title-box">用户信息</div>
    <div class="filter-box">
      <el-form ref="filterFormRef" :inline="true" :model="form" label-width="auto">
        <el-form-item label="用户名:" prop="username">
          <el-input v-model="form.username" placeholder="请输入" clearable />
        </el-form-item>
        <el-form-item label="年龄:" prop="age">
          <el-input v-model="form.age" placeholder="请输入" clearable />
        </el-form-item>
        <el-form-item label="性别:" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择" clearable>
            <el-option v-for="sex in sexOptions" :key="sex.id" :label="sex.label" :value="sex.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="角色:" prop="role">
          <el-select v-model="form.role" placeholder="请选择" clearable>
            <el-option v-for="role in roleOptions" :key="role.id" :label="role.label" :value="role.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="创建日期：" prop="createdAt">
          <el-date-picker
            v-model="form.createdAt"
            type="date"
            placeholder="请选择"
            clearable
          />
        </el-form-item>
      </el-form>
      <div class="btn-group">
        <el-button v-if="btnsPremissan.includes(4001)" type="primary" :icon="Search" @click="searchHandle"
          >搜索</el-button
        >
        <el-button v-if="btnsPremissan.includes(4002)" type="primary" :icon="Pointer" @click="resetFilterForm"
          >重置</el-button
        >
        <el-button v-if="btnsPremissan.includes(4003)" type="primary" :icon="Plus" plain @click="addHandle"
          >新增用户</el-button
        >
      </div>
    </div>
</template>

<script setup name="user">
import { ref, reactive, toRaw } from "vue";
import { Search, Plus, Delete, Edit, Upload, Pointer } from "@element-plus/icons-vue";
import {useMenusStore} from '@/stores/menus';
import { storeToRefs } from "pinia";

const props = defineProps(['sexOptions', 'roleOptions'])
const emit = defineEmits(['search', 'add'])
const menusStore = useMenusStore()
const { btnsPremissan } = storeToRefs(menusStore)

const filterFormRef = ref(null)
const form = reactive({
  username: "",
  age: "",
  sex: "",
  role: "",
  createdAt: "",
});


const searchHandle = () => {
  emit('search', {...form, page: 1})
};

const resetFilterForm = () => {
  filterFormRef.value.resetFields()
  emit('search', {...form, page: 1})
}

const addHandle = () => {
  emit('add')
};

</script>

<style lang="less" scoped>

.title-box {
  padding: 20px;
  font-size: 20px;
  font-weight: bold;
}

.filter-box {
  background-color: #fff;
  padding: 20px;
  .el-input {
    --el-input-width: 220px;
  }

  .el-select {
    --el-select-width: 220px;
  }
  .btn-group {
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
}

</style>
